library("magrittr")
library("png")
library("imager")
library("dplyr")
library("tidyr")
library("ggplot2")
library("jpeg")
library("grid")
library("plotly")
library("brocks")
library("ggpubr")
setwd("/Users/davidizquierdogomez/Desktop/schemalegende")
grid <- as_tibble(rep(seq(0, 10, by = 0.5), 21)) %>%
arrange(value) %>%
cbind(rep(seq(0, 10, by = 0.5), 21), rep(0, 441)) %>%
rename(x = "value") %>%
rename(y = "rep(seq(0, 10, by = 0.5), 21)") %>%
rename(n = "rep(0, 441)") %>%
mutate(n = as.character(n)) %>%
# mutate(x = as.character(x), y = as.character(y)) %>%
# mutate(n = as.character(n)) %>%
arrange(x, y)
image_destination <- "https://raw.githubusercontent.com/davidizquierdogomez/pictures/main/hellocellschema.png"
ggrid <- ggplot(data = grid, aes(x = x, y = y)) +
geom_point(size = 1, colour = "red") +
scale_y_continuous(expand = c(0,0), limits = c(0, max(grid$y))) +
scale_x_continuous(expand = c(0,0), limits = c(0, max(grid$x))) +
# geom_text(aes(label = n), vjust = 1.5, colour = "black") +
theme_bw() +
theme(plot.title = element_text(size = rel(1.5), face = "bold", vjust = 1.5),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
plot.margin = unit(c(4,0,0,4), "cm")) + #plot margins margin(t,r,b,l)
ggtitle("Cellule eucaryote") +
theme(plot.title = element_text(size = 15, hjust = 0.5, colour = "red")) +
labs(x="David Izquierdo")
ppgrid <- ggplotly(ggrid, width = 800, height = 600) %>%
config(displayModeBar = F)
ttgrid <- plotly::layout(ppgrid,
autosize = TRUE,
xaxis = list(showgrid = F),
yaxis = list(showgrid = F),
images = list(
list(
source = image_destination,
xref = "x",
yref = "y",
x = 0,
y = 10,
sizex = 10,
sizey = 10,
sizing = "stretch",
opacity = 0.9,
layer = "below"
)
))
ttgrid
Final Interactive figure
# FINAL COORDINATES
# create the vectors
xfinal <- c(4.50, 1.50, 3.00, 7.00, 1.00, 7.00, 6.50, 5.00, 4.00, 6.00, 5.00, 9.50, 9.50, 5.00, 1.50, 4.50, 5.40, 5.00)
yfinal <- c(8.00, 6.00, 4.00, 6.50, 4.50, 4.50, 8.00, 3.00, 5.50, 6.50, 1.00, 7.50, 5.50, 9.50, 5.00, 3.50, 9.00, 8.50)
labelfinal <- c("Nucléole",
"Centrosome",
"Mitochondrie",
"Mitochondrie",
"Cytosquelette",
"Golgi",
"Lysosome",
"Lysosome",
"Ret.End.Rugueux",
"Ret.End.Lisse",
"Membrane Plasmique",
"Cils",
"Cils",
"Enveloppe nucléaire",
"Ribosome",
"Cytoplasme",
"Pore nucléaire",
"Chromatine")
# bind the vectors into a tibble
coo_cellule <- cbind(xfinal, yfinal) %>%
as_tibble(xfinal, yfinal) %>%
mutate(label = labelfinal) %>%
rename(x = xfinal, y = yfinal) %>%
arrange(x, y)
gg <- ggplot(data = coo_cellule, aes(x = x, y = y, text = label)) +
geom_point(size = 2, pch = 21, bg="black", lwd=2, colour = "yellow") +
scale_y_continuous(expand = c(0,0), limits = c(0, max(grid$y))) +
scale_x_continuous(expand = c(0,0), limits = c(0, max(grid$x))) +
theme_bw() +
theme(plot.title = element_text(size = rel(1.5), face = "bold", vjust = 1.5),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
# panel.border = element_rect(colour = "white", fill=NA, size=1),
plot.margin = unit(c(4,0,0,4), "cm")) + #plot margins margin(t,r,b,l)
ggtitle("Cellule eucaryote") +
theme(plot.title = element_text(size = 25, hjust = 0.5, colour = "red")) +
labs(x="David Izquierdo")
## Warning: Duplicated aesthetics after name standardisation: size
pp <- ggplotly(gg, width = 800, height = 600, tooltip = "label") %>%
config(displayModeBar = F)
tt <- plotly::layout(pp,
autosize = TRUE,
xaxis = list(showgrid = F),
yaxis = list(showgrid = F),
images = list(
list(
source = image_destination,
xref = "x",
yref = "y",
x = 0,
y = 10,
sizex = 10,
sizey = 10,
sizing = "stretch",
opacity = 0.9,
layer = "below"
)
))
tt
CORRECTION
# the image must be fetched locally
img <- readPNG("/Users/davidizquierdogomez/Desktop/schemalegende/hellocellschema.png")
plotcorrection <- ggplot(coo_cellule,aes(x=x,y=y)) +
annotation_custom(rasterGrob(img, width = unit(1,"npc"), height = unit(1,"npc")),
-Inf, Inf, -Inf, Inf) +
scale_y_continuous(expand = c(0,0), limits = c(0, 10)) +
scale_x_continuous(expand = c(0,0), limits = c(0, 10)) +
geom_point(size = 2, pch = 21, bg="black", colour = "yellow") +
ggrepel::geom_label_repel(aes(label = label), size = 5) +
theme_bw() +
theme(plot.title = element_text(size = rel(1.5), face = "bold", vjust = 1.5),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
panel.border = element_rect(colour = "white", fill = NA, size = 1),
panel.background = element_blank()) +
ggtitle("\nCellule eucaryote\n\n") +
theme(plot.title = element_text(size = 20, hjust = 0.5, colour = "red")) +
labs(x="David Izquierdo")
plotcorrection